package org.itstack.config;

import org.itstack.OrderLogicFilter;
import org.itstack.filter.OrderPriorityFilter;
import org.itstack.filter.OrderTimeFilter;
import org.itstack.filter.LocationFilter;
import org.itstack.OrderTypeFilter;
import org.itstack.OrderAmountFilter;
import org.itstack.CustomerLevelFilter;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 扩展的订单引擎配置类
 * 包含所有新增的过滤器
 */
public class ExtendedOrderEngineConfig {
    
    private static Map<String, OrderLogicFilter> logicFilterMap;
    
    static {
        logicFilterMap = new ConcurrentHashMap<>();
        
        // 原有过滤器
        logicFilterMap.put("orderType", new OrderTypeFilter());
        logicFilterMap.put("orderAmount", new OrderAmountFilter());
        logicFilterMap.put("customerLevel", new CustomerLevelFilter());
        
        // 新增过滤器
        logicFilterMap.put("orderPriority", new OrderPriorityFilter());
        logicFilterMap.put("orderTime", new OrderTimeFilter());
        logicFilterMap.put("location", new LocationFilter());
    }
    
    public static Map<String, OrderLogicFilter> getLogicFilterMap() {
        return logicFilterMap;
    }
    
    public static void setLogicFilterMap(Map<String, OrderLogicFilter> logicFilterMap) {
        ExtendedOrderEngineConfig.logicFilterMap = logicFilterMap;
    }
    
    /**
     * 动态添加过滤器
     */
    public static void addFilter(String key, OrderLogicFilter filter) {
        logicFilterMap.put(key, filter);
        System.out.println("动态添加过滤器: " + key);
    }
    
    /**
     * 动态移除过滤器
     */
    public static void removeFilter(String key) {
        OrderLogicFilter removed = logicFilterMap.remove(key);
        if (removed != null) {
            System.out.println("动态移除过滤器: " + key);
        }
    }
    
    /**
     * 获取过滤器数量
     */
    public static int getFilterCount() {
        return logicFilterMap.size();
    }
    
    /**
     * 检查过滤器是否存在
     */
    public static boolean hasFilter(String key) {
        return logicFilterMap.containsKey(key);
    }
}
